import { http } from '@/utils/http'
import {
  OrderPre,
  OrderDetail,
  WxPayResult,
  OrderListResult
} from '@/types/order'
import { OrderState } from '@/enums'

// 获取预付订单
export const getOrderPre = () => {
  return http<OrderPre>({
    url: '/member/order/pre'
  })
}

// 提交订单
export const submitOrder = (data: object) => {
  return http<{ id: string }>({
    url: '/member/order',
    method: 'POST',
    data
  })
}

// 获取立即购买数据
export const getOrderPreNow = (data: object) => {
  return http<OrderPre>({
    url: '/member/order/pre/now',
    data
  })
}

// 获取订单详情
export const getOrderDetail = (id: string) => {
  return http<OrderDetail>({
    url: `/member/order/${id}`
  })
}

// 获取预付单信息
export const getWxPay = (orderId: string) => {
  return http<WxPayResult>({
    url: '/pay/wxPay/miniPay',
    data: {
      orderId
    }
  })
}

// 模拟支付
export const mockPay = (orderId: string) => {
  return http({
    url: '/pay/mock',
    data: { orderId }
  })
}

// 获取订单列表
export const getOrderList = (data: {
  page: number
  pageSize: number
  orderState: OrderState
}) => {
  return http<OrderListResult>({
    url: '/member/order',
    data
  })
}
